package bancosys.tec.utils.db.converter;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Converter for Oracle.
 */
public class OracleConverter extends StatementDbConverter {

    /**
     * C'tor
     * 
     * @param inputFile the input file
     * @param outputFile the output file
     * @param dbName the database name
     * @throws FileNotFoundException if the input file is not found
     * @throws MalformedURLException if the input file uri is incorrect
     */
    public OracleConverter(File inputFile, File outputFile, String dbName) throws FileNotFoundException, MalformedURLException {
        super(inputFile, outputFile, dbName);
    }

    /**
     * C'tor
     * 
     * @param inputFile the input url
     * @param outputFile the output file
     * @param dbName the database name
     */
    public OracleConverter(URL inputFile, File outputFile, String dbName) {
        super(inputFile, outputFile, dbName);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String convertStatement(String s) {
        String tmp = s;

        // Ignore
        if (tmp.startsWith("COMMENT")) {
            tmp = tmp.replaceAll(";", ".");
        }

        return tmp;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getHeader() {
        return "";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean gotDelimiter(String line) {
        return line.matches("^" + this.getOldStatementDelimiterChar() + "$");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected char getOldStatementDelimiterChar() {
        return '/';
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected char getNewStatementDelimiterChar() {
        return ';';
    }
}
